<?php

namespace App\Admin\Controllers;

use App\Models\Notice;
use Encore\Admin\Controllers\AdminController as Controller;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class NoticeController extends Controller
{
    protected $title = "通知管理";

    protected function grid()
    {
        $grid = new Grid(new Notice);

        $grid->id('ID');
        $grid->title('标题');
        $grid->content('详情');
        $grid->status('是否显示')->switch([
            'on' => ['value' => 1, 'text' => '显示', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '隐藏', 'color' => 'danger'],
        ]);
        $grid->created_at('创建时间');
        $grid->updated_at('最后更新时间');

        return $grid;
    }

    protected function detail($id)
    {
        $show = new Show(Notice::findOrFail($id));

        $show->id('ID');
        $show->title('标题');
        $show->content('详情');
        $show->status('状态');
        $show->created_at('创建时间');
        $show->updated_at('最后更新时间');

        return $show;
    }

    protected function form()
    {
        $form = new Form(new Notice);

        $form->text('title', '标题');
        $form->textarea('content', '详情');
        $form->switch('status', '是否显示')->states([
            'on' => ['value' => 1, 'text' => '显示', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '隐藏', 'color' => 'danger'],
        ]);
        return $form;
    }
}
